Ext.define('Ext.app.NoticePortlet', {
    extend: 'Ext.grid.Panel',
    alias: 'widget.gridportlet',
    height: 180,
    change: function(val) {
        if (val > 0) {
            return '<span style="color:green;">' + val + '</span>';
        } else if (val < 0) {
            return '<span style="color:red;">' + val + '</span>';
        }
        return val;
    },

    initComponent: function(){
        var store = Ext.create('Ext.data.Store', {
            fields: [
               {name: 'title'},
               {name: 'content'}
            ],
		    proxy: {
		        type: 'ajax',
		        url: '/resourcecontrol/notice_list/',
		        actionMethods:'post',
		        reader: {
		            type: 'json',
		            root: 'rows',
		            totalProperty: 'totalCount'
		        }
		    },
		    autoLoad: true
        });

        Ext.apply(this, {
            height: this.height,
            store: store,
            stripeRows: true,
            columnLines: true,
            columns: [{
                text   : '标题',
                sortable : false,
                width: 160,
                dataIndex: 'title'
            },{
                text   : '内容',
                sortable : false,
                flex: 1,
                dataIndex: 'content'
            }]
        });

        this.callParent(arguments);
	    Ext.TaskManager.start({
		    run: function(){
		        store.load();
		    },
		    interval:300000  //5分钟
	    });         
    }
});

